package com.netty.httpserver;

import java.util.List;
import java.util.Map;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.QueryStringDecoder;

public class HttpServletRequest {
	
	@SuppressWarnings("unused")
	private ChannelHandlerContext ctx;
	
	private HttpRequest req;
	public HttpServletRequest(ChannelHandlerContext ctx, HttpRequest req) {
		super();
		this.ctx = ctx;
		this.req = req;
	}

	@SuppressWarnings("deprecation")
	public String getUri() {
		return req.getUri();
	}
	public Map<String, List<String>> getParameters() {
		QueryStringDecoder decoder = new QueryStringDecoder(getUri());
		Map<String, List<String>> parameters = decoder.parameters();
		return parameters;
	}
	 
	public String getParameter(String paramKey) {
		Map<String, List<String>> parameters = getParameters();
		if (parameters != null ) {
			List<String> list = parameters.get(paramKey);
			if (list != null) {
				return list.get(0);
			}
		}
		return null;
	}
	

}
